from bs4 import BeautifulSoup
import requests
import xlwt

url = "https://space.bilibili.com/132344841/video"
response = requests.get(url)
html_content = response.text
soup = BeautifulSoup(html_content, 'html.parser')
title_elements = soup.find_all(class_="title")
titles = [title.text for title in title_elements]

for title in titles:
    print(title)

# 创建Excel工作簿和工作表
workbook = xlwt.Workbook()
sheet = workbook.add_sheet('Bilibili Titles')

# 写入标题行
sheet.write(0, 0, 'Title')

# 写入标题内容
for i, title in enumerate(titles):
    sheet.write(i + 1, 0, title)

# 保存Excel文件
workbook.save('D:\\bilibili_titles.xls')